<?php
//include "GenFunction.php";

?>
<?php 
	
	Class Gen_Stat_In
{
	//поля
	var $id;
	var $datetime;//при загрузке надо отсортировать по датетайму
	var $pr_id;
	var $call;
	var $min;
	var $waste;
	var $service;
	
	var $db_name;
	
			
			function Gen_Stat_In($array_projs_id=array(),$array_datetimes=array(),$day=false)
			// function Gen_Stat_In($array_datetimes=,$array_projs_id=)
	{
		if($day)$this->db_name='stat_in_days';
		else $this->db_name='stat_in';
		
		if(empty($array_datetimes))$array_datetimes=array_datetimes_autoGen(5);
		if(empty($array_projs_id))$array_projs_id=array_int_noreapet_autoGen(10);
		
		$this->CreateTable();
		
			foreach($array_datetimes as $datetime)
		{
				foreach($array_projs_id as $proj_id)
				{
					
					$this->id++;
					$this->GenerateData($datetime,$proj_id);
					$this->InsertData();
					// $this->Show_row($day);
					
				}
		}
		echo $this->db_query.'<br><br>';
	}
		function GenerateData($dt,$pr_id)
	{
			$this->datetime=$dt;
			$this->pr_id=$pr_id;
			$this->call=gen_int();
			$this->min=gen_int();
			$this->waste=gen_double();
			$this->service=gen_double();
	}
	
		function Show_row()
		{
			echo$this->id.'		';
			echo$this->datetime.'		';
			echo$this->pr_id.'		';
			echo$this->call.'		';
			echo$this->min.'		';
			echo$this->waste.'		';
			echo$this->service.'		';
			echo '<br>';
		}
		
		function CreateTable()
		{
			$db=$this->db_name;
			
			$this->db_query.="CREATE TABLE `$db` (
  `id` int(11) NOT NULL auto_increment,
  `datetime` datetime NOT NULL,
  `pr_id` int(11) NOT NULL,
  `call` int(11) NOT NULL,
  `min` int(11) NOT NULL,
  `waste` double NOT NULL,
  `service` double NOT NULL,
  PRIMARY KEY  (`id`),
  FOREIGN KEY (pr_id) REFERENCES projects(id)
           ON UPDATE CASCADE
           ON DELETE CASCADE
       ) ENGINE=InnoDB CHARACTER SET=UTF8;
	   ".'<br><br>';
		}
		
			function InsertData()
		{
			$id=$this->id;
			$datetime=$this->datetime;
			$pr_id=$this->pr_id;
			$call=$this->call;
			$min=$this->min;
			$waste=$this->waste;
			$service=$this->service;
			
			$db=$this->db_name;
			$this->db_query.="INSERT INTO `$db` (`datetime`, `pr_id`, `call`, `min`, `waste`, `service`)
				VALUES ('$datetime', '$pr_id', '$call', '$min', '$waste', '$service');"."<br>";
		}
				
}

// $gsi=new Gen_Stat_In();

		 ?>